Skip to content

fix(cli): resolve tsconfig aliases in database seeds - #873

Closed
karthickeyan-dev wants to merge 12 commits into
voidzero-dev:mainfrom
karthickeyan-dev:fix/db-seed-tsconfig-paths-872
Closed

karthickeyan-dev wants to merge 12 commits into
voidzero-dev:mainfrom
karthickeyan-dev:fix/db-seed-tsconfig-paths-872

Conversation

@karthickeyan-dev

@karthickeyan-dev karthickeyan-dev commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

void db seed now resolves seed and schema imports using the application's tsconfig paths, including @auth-schema references used by foreign keys.

Build a runtime path map with get-tsconfig, excluding .d.ts, .d.mts, and .d.cts targets while preserving inheritance, base URLs, wildcards, and fallback targets. This prevents generated aliases such as void/routes from replacing runtime helpers with declarations. Jiti receives a temporary config that remains available through seed execution and is removed afterwards.

Regression coverage exercises auth foreign keys, schema files and directories, generated declaration aliases with routeUrl(), mixed declaration/runtime targets, dynamic imports, and CommonJS JavaScript seeds. The seeding guide documents alias support.

Closes #872.

Validation:

  • Seed tests: 13 passed, including reproduction of the reviewed failure before the fix
  • vp run build:all, vp check, vp run check:types, and build-artifact checks
  • vp run test --list and vp run test
  • vp test run: 827 files and 17,827 tests passed; 1 file and 39 tests skipped
  • Full packed npm/pnpm matrix across React, Vue, Svelte, and Solid
  • Packed Vite+ starter checks with npm and pnpm
  • Freshly installed CLI: void prepare followed by a SQLite seed using generated aliases, routeUrl(), and a dynamic @schema import

@karthickeyan-dev
karthickeyan-dev requested a review from a team as a code owner November 18, 2026 05:40

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TypeScript case looks good now and routeUrl() still works. The JavaScript behavior worries me though. Can we make .mjs and ESM .js use the same alias resolution as .ts, including for await import()?

Right now, with the same import and tsconfig, seed.ts seeds from the local fixture, but seed.mjs seeds from node_modules if there’s a package with the same name. Changing the file extension shouldn’t change what data ends up in the database.

One smaller thing: a seed that doesn’t use aliases used to work before void prepare. Now it fails if .void/tsconfig.json is missing. Can we update it so the error tells people to run void prepare?

cpojer
cpojer previously approved these changes Nov 19, 2026

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T08:15:07.504939Z fa6ea31 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f46892910a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/cli/db-seed-loader.ts Resolved
Comment thread packages/void/src/cli/db-seed-loader.ts Resolved
Fall back to jiti when node:module has no registerHooks (Bun), resolve
extensionless subpaths into packages without exports, load .tsx helpers,
and skip .json files for path targets as TypeScript does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

Merged main and pushed a few follow-ups:

  • 6e817b71f: the loader now passes the new lint rules on main (no regex, named SeedModuleLoader type, no non-null assertion).
  • a33334700: fixes for seeds in apps whose tsconfig has paths/baseUrl, each one a regression from the jiti loader on main:
    • Bun has no registerHooks, so it falls back to jiti again.
    • Extensionless subpaths into packages without exports (lodash/range, dayjs/plugin/utc) resolve again.
    • .tsx helpers load.
    • A path target never resolves to a .json file that sits beside it, matching TypeScript.
    • Docs paragraph trimmed to the user-facing part.

Known limits I left as they are:

  • export { SomeType } from './types' written without type fails to link under native ESM. TypeScript with isolatedModules reports the same thing.
  • A missing tsconfig base other than .void/tsconfig.json (for example $app/tsconfig before svelte-kit sync) stops the seed before any reset, and the error names the file.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a33334700c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/cli/db-seed-loader.ts Resolved
Brooooooklyn and others added 2 commits November 25, 2026 15:29
App modules get named exports from JSON files and CommonJS modules,
ESM-syntax JavaScript in a CommonJS app keeps require and __dirname, and
extensionless absolute paths resolve as relative ones do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Running a CommonJS module inside the load hook changed evaluation order,
could hit Node's require(esm) race guard, and changed what packages in
node_modules received. CommonJS imports keep Node's export detection.
JSON named exports now skip a byte order mark, __proto__, and malformed
keys, and Windows drive paths get the extension fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b7b35b8e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/cli/db-seed-loader.ts Resolved
Comment thread packages/void/src/cli/db-seed-loader.ts Resolved
@karthickeyan-dev
karthickeyan-dev deleted the fix/db-seed-tsconfig-paths-872 branch November 25, 2026 07:57
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@Brooooooklyn

Copy link
Copy Markdown
Member

This PR was closed and its branch deleted before my last push, so 81a4e33b3, which my two latest thread replies name, never landed here. The work continues in #919, which keeps @karthickeyan-dev's commits and includes that commit. Thanks for the original fix!

Brooooooklyn added a commit that referenced this pull request Nov 25, 2026
`void db seed` now resolves the path aliases in the app's
`tsconfig.json` (such as `@schema` and `@auth-schema`) in seed files and
schema modules, including dynamic `import()`. Closes #872.

This continues #873 by @karthickeyan-dev, which was closed with its
branch deleted. Their commits are kept as they were.

## How it works

```
seed / schema import
├─ Node with tsconfig paths or baseUrl
│   └─ node:module registerHooks
│       ├─ aliases: app modules only (not node_modules or other packages)
│       ├─ .d.ts targets skipped, so `void/routes` keeps its runtime code
│       ├─ .ts/.tsx/.mts/.cts compiled with esbuild
│       └─ keeps jiti's leniency: extensionless paths, `lodash/range`,
│          named JSON imports, require/__dirname in promoted .js
└─ no paths, or Bun (no registerHooks) → jiti, as before
```

A missing `.void/tsconfig.json` stops the seed before the reset and says
to run `void prepare`.

## Known limits

- CommonJS named imports use Node's export detection. A package whose
names Node cannot see needs a default import.
- `export { SomeType } from './types'` without `type` fails to link.
TypeScript's `isolatedModules` reports the same thing.

## Verification

- `packages/void/test/unit/db-seed.test.ts`: 36 tests. Each case added
after #873's last commit failed before its fix.
- `vp check`, `vp run test` (178/178 tasks).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: karthic <jkarthickeyan24@gmail.com>
Co-authored-by: Christoph Nakazawa <cnakazawa@cloudflare.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa6ea31ff6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return { format: 'commonjs', source: code, shortCircuit: true };
}
const loader = sourcefile.endsWith('.tsx') ? 'tsx' : 'ts';
return { format: 'module', source: compileToEsm(sourcefile, loader), shortCircuit: true };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve CommonJS exports in TypeScript seed modules

On Node, when runtime paths or baseUrl enables this loader, a CommonJS-style .ts seed such as exports.seed = async () => {} is compiled to ESM. Esbuild exposes its CommonJS exports object as a single default export, but importModule only unwraps Node's module.exports marker. Consequently, loadSeedFunction finds neither mod.seed nor a function-valued mod.default and rejects a named seed that Jiti previously loaded. The same conversion makes loadSeedSchema discard CommonJS schema exports when it filters out default. Preserve CommonJS output or normalize its generated wrapper instead of unconditionally promoting these TypeScript modules to ESM.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

void db seed cannot resolve @auth-schema imports in database schemas

3 participants